﻿
using FacebookXmpp.Parse;

namespace FacebookXmpp.Stanzas
{
	internal class StreamStream : Stanza
	{
		public StreamStream( )
		{
			NextResponse = string.Format( @"<stream:stream id='{0}' to='chat.facebook.com' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' >", NextId );
		}

		internal override StanzaListenCriteria ListenFor
		{
			get { return new StanzaListenCriteria( "stream:stream", true ); }
		}

        public override void ProcessResponse(MessageData recieved)
		{
			if (recieved.HasChildren)
				foreach (MessageData data in recieved.GetChildren())
					Stream.InjectStream( data );

			Stream.AddHandler( new StreamFeatures( ) );
			Stream.RemoveHandler( this );
		}
	}
}
